﻿namespace DataGridViewPrint
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.Windows.Forms;

    public class PrintOptions : Form
    {
        protected Button btnCancel;
        protected Button btnOK;
        internal CheckBox chkFitToPageWidth;
        internal CheckedListBox chklst;
        private IContainer components;
        internal GroupBox gboxRowsToPrint;
        internal Label lblColumnsToPrint;
        internal Label lblTitle;
        private PageSetupDialog pageSetupDialog1;
        private PrintDialog printDialog1;
        private PrintDocument printDocument1;
        private PrintPreviewDialog printPreviewDialog1;
        internal RadioButton rdoAllRows;
        internal RadioButton rdoSelectedRows;
        internal TextBox txtTitle;

        public PrintOptions()
        {
            this.components = null;
            this.InitializeComponent();
        }

        public PrintOptions(List<string> availableFields, string title)
        {
            this.components = null;
            this.InitializeComponent();
            this.txtTitle.Text = title;
            foreach (string str in availableFields)
            {
                this.chklst.Items.Add(str, true);
            }
            this.chklst.Enabled = false;
            this.rdoAllRows.Checked = true;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Cancel;
            base.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.OK;
            base.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        public List<string> GetSelectedColumns()
        {
            List<string> list = new List<string>();
            foreach (object obj2 in this.chklst.CheckedItems)
            {
                list.Add(obj2.ToString());
            }
            return list;
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(PrintOptions));
            this.rdoSelectedRows = new RadioButton();
            this.rdoAllRows = new RadioButton();
            this.chkFitToPageWidth = new CheckBox();
            this.lblTitle = new Label();
            this.txtTitle = new TextBox();
            this.gboxRowsToPrint = new GroupBox();
            this.lblColumnsToPrint = new Label();
            this.btnOK = new Button();
            this.btnCancel = new Button();
            this.chklst = new CheckedListBox();
            this.printPreviewDialog1 = new PrintPreviewDialog();
            this.pageSetupDialog1 = new PageSetupDialog();
            this.printDocument1 = new PrintDocument();
            this.printDialog1 = new PrintDialog();
            this.gboxRowsToPrint.SuspendLayout();
            base.SuspendLayout();
            this.rdoSelectedRows.AutoSize = true;
            this.rdoSelectedRows.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.rdoSelectedRows.Location = new Point(0x5b, 0x12);
            this.rdoSelectedRows.Name = "rdoSelectedRows";
            this.rdoSelectedRows.Size = new Size(0x40, 0x11);
            this.rdoSelectedRows.TabIndex = 1;
            this.rdoSelectedRows.TabStop = true;
            this.rdoSelectedRows.Text = "选择行";
            this.rdoSelectedRows.UseVisualStyleBackColor = true;
            this.rdoSelectedRows.CheckedChanged += new EventHandler(this.rdoSelectedRows_CheckedChanged);
            this.rdoAllRows.AutoSize = true;
            this.rdoAllRows.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.rdoAllRows.Location = new Point(9, 0x12);
            this.rdoAllRows.Name = "rdoAllRows";
            this.rdoAllRows.Size = new Size(0x40, 0x11);
            this.rdoAllRows.TabIndex = 0;
            this.rdoAllRows.TabStop = true;
            this.rdoAllRows.Text = "全部行";
            this.rdoAllRows.UseVisualStyleBackColor = true;
            this.rdoAllRows.CheckedChanged += new EventHandler(this.rdoAllRows_CheckedChanged);
            this.chkFitToPageWidth.AutoSize = true;
            this.chkFitToPageWidth.CheckAlign = ContentAlignment.MiddleRight;
            this.chkFitToPageWidth.FlatStyle = FlatStyle.System;
            this.chkFitToPageWidth.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.chkFitToPageWidth.Location = new Point(0xbb, 0x48);
            this.chkFitToPageWidth.Name = "chkFitToPageWidth";
            this.chkFitToPageWidth.Size = new Size(0x54, 0x12);
            this.chkFitToPageWidth.TabIndex = 0x15;
            this.chkFitToPageWidth.Text = "适应页宽";
            this.chkFitToPageWidth.UseVisualStyleBackColor = true;
            this.lblTitle.AutoSize = true;
            this.lblTitle.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.lblTitle.Location = new Point(0xb8, 0x63);
            this.lblTitle.Name = "lblTitle";
            this.lblTitle.Size = new Size(0x3b, 13);
            this.lblTitle.TabIndex = 20;
            this.lblTitle.Text = "标题设置";
            this.txtTitle.AcceptsReturn = true;
            this.txtTitle.Location = new Point(0xb8, 0x72);
            this.txtTitle.Multiline = true;
            this.txtTitle.Name = "txtTitle";
            this.txtTitle.ScrollBars = ScrollBars.Vertical;
            this.txtTitle.Size = new Size(0xb0, 0x6c);
            this.txtTitle.TabIndex = 0x13;
            this.gboxRowsToPrint.Controls.Add(this.rdoSelectedRows);
            this.gboxRowsToPrint.Controls.Add(this.rdoAllRows);
            this.gboxRowsToPrint.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.gboxRowsToPrint.Location = new Point(0xb8, 20);
            this.gboxRowsToPrint.Name = "gboxRowsToPrint";
            this.gboxRowsToPrint.Size = new Size(0xad, 0x27);
            this.gboxRowsToPrint.TabIndex = 0x12;
            this.gboxRowsToPrint.TabStop = false;
            this.gboxRowsToPrint.Text = "打印行范围";
            this.lblColumnsToPrint.AutoSize = true;
            this.lblColumnsToPrint.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.lblColumnsToPrint.Location = new Point(8, 8);
            this.lblColumnsToPrint.Name = "lblColumnsToPrint";
            this.lblColumnsToPrint.Size = new Size(0x62, 13);
            this.lblColumnsToPrint.TabIndex = 0x11;
            this.lblColumnsToPrint.Text = "选择要打印的列";
            this.btnOK.BackColor = SystemColors.Control;
            this.btnOK.Cursor = Cursors.Default;
            this.btnOK.FlatStyle = FlatStyle.System;
            this.btnOK.Font = new Font("Arial", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0xb2);
            this.btnOK.ForeColor = SystemColors.ControlText;
            this.btnOK.Image = (Image) manager.GetObject("btnOK.Image");
            this.btnOK.ImageAlign = ContentAlignment.MiddleRight;
            this.btnOK.Location = new Point(0xdb, 0xe4);
            this.btnOK.Name = "btnOK";
            this.btnOK.RightToLeft = RightToLeft.No;
            this.btnOK.Size = new Size(0x4b, 0x17);
            this.btnOK.TabIndex = 14;
            this.btnOK.Text = "打印";
            this.btnOK.UseVisualStyleBackColor = false;
            this.btnOK.Click += new EventHandler(this.btnOK_Click);
            this.btnCancel.BackColor = SystemColors.Control;
            this.btnCancel.Cursor = Cursors.Default;
            this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.FlatStyle = FlatStyle.System;
            this.btnCancel.Font = new Font("Arial", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0xb2);
            this.btnCancel.ForeColor = SystemColors.ControlText;
            this.btnCancel.Image = (Image) manager.GetObject("btnCancel.Image");
            this.btnCancel.Location = new Point(300, 0xe4);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.RightToLeft = RightToLeft.No;
            this.btnCancel.Size = new Size(0x38, 0x17);
            this.btnCancel.TabIndex = 15;
            this.btnCancel.Text = "取消";
            this.btnCancel.UseVisualStyleBackColor = false;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            this.chklst.CheckOnClick = true;
            this.chklst.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0);
            this.chklst.FormattingEnabled = true;
            this.chklst.Location = new Point(8, 0x1a);
            this.chklst.Name = "chklst";
            this.chklst.Size = new Size(170, 0xd6);
            this.chklst.TabIndex = 13;
            this.printPreviewDialog1.AutoScrollMargin = new Size(0, 0);
            this.printPreviewDialog1.AutoScrollMinSize = new Size(0, 0);
            this.printPreviewDialog1.ClientSize = new Size(400, 300);
            this.printPreviewDialog1.Enabled = true;
            this.printPreviewDialog1.Icon = (Icon) manager.GetObject("printPreviewDialog1.Icon");
            this.printPreviewDialog1.Name = "printPreviewDialog1";
            this.printPreviewDialog1.Visible = false;
            this.printDialog1.UseEXDialog = true;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x171, 260);
            base.Controls.Add(this.chkFitToPageWidth);
            base.Controls.Add(this.lblTitle);
            base.Controls.Add(this.txtTitle);
            base.Controls.Add(this.gboxRowsToPrint);
            base.Controls.Add(this.lblColumnsToPrint);
            base.Controls.Add(this.btnOK);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.chklst);
            base.FormBorderStyle = FormBorderStyle.FixedToolWindow;
            this.MinimumSize = new Size(0x121, 0x11c);
            base.Name = "PrintOptions";
            base.SizeGripStyle = SizeGripStyle.Show;
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "打印设置";
            base.Load += new EventHandler(this.PrintOtions_Load);
            this.gboxRowsToPrint.ResumeLayout(false);
            this.gboxRowsToPrint.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void PrintOtions_Load(object sender, EventArgs e)
        {
            this.rdoAllRows.Checked = true;
            this.chkFitToPageWidth.Checked = true;
        }

        private void rdoAllRows_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rdoAllRows.Checked)
            {
                this.chklst.Enabled = false;
            }
        }

        private void rdoSelectedRows_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rdoSelectedRows.Checked)
            {
                this.chklst.Enabled = true;
            }
        }

        public bool FitToPageWidth
        {
            get
            {
                return this.chkFitToPageWidth.Checked;
            }
        }

        public bool PrintAllRows
        {
            get
            {
                return this.rdoAllRows.Checked;
            }
        }

        public string PrintTitle
        {
            get
            {
                return this.txtTitle.Text;
            }
        }
    }
}

